package com.bdqn.controller;

import com.bdqn.pojo.SysUser;
import com.bdqn.service.SysUserService;
import com.bdqn.service.SysUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user")
public class SysUserController extends HttpServlet {
    private SysUserService sysUserService = new SysUserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String opr=request.getParameter("opr");
        switch (opr){
            case "login":
                String account = request.getParameter("account");
                String password= request.getParameter("password");
                SysUser loginUser = sysUserService.login(account,password);
                request.getSession().setAttribute("USER_SESSION",loginUser);
                request.getRequestDispatcher("WEB-INF/jsp/frame.jsp").forward(request,response);
                break;
            default:
                break;
        }
    }
}
